home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Program th234947252001.psc / clsUpdate.cls next >
Encoding:
Visual Basic class definition  |  2001-07-25  |  3.3 KB  |  133 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsUpdate"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Private Declare Function CoFreeUnusedLibraries Lib "ole32" () As Long
  17. Private Const RegSvr32 = "regsvr32.exe"
  18.  
  19. Private pSourceLib As String
  20. Private pDestLib As String
  21. Private pBackupLib As String
  22.  
  23.  
  24. Public Property Get SourceLib() As String
  25.     SourceLib = pSourceLib
  26. End Property
  27. Public Property Let SourceLib(ByVal NewVal As String)
  28.     If FileExists(NewVal) Then
  29.         pSourceLib = NewVal
  30.     Else
  31.         Err.Raise vbObjectError, "DestLib", "File not found."
  32.     End If
  33. End Property
  34.  
  35. Public Property Get DestLib() As String
  36.     DestLib = pDestLib
  37. End Property
  38. Public Property Let DestLib(ByVal NewVal As String)
  39.     If FileExists(NewVal) Then
  40.         pBackupLib = GetTempFileName(NewVal)
  41.         pDestLib = NewVal
  42.     Else
  43.         Err.Raise vbObjectError, "DestLib", "File not found."
  44.     End If
  45. End Property
  46.  
  47. Public Property Get BackupLib() As String
  48.     BackupLib = pBackupLib
  49. End Property
  50.  
  51.  
  52.  
  53. Public Function Update() As Boolean
  54.     
  55.     If SourceLib = "" And DestLib = "" Then
  56.         Err.Raise vbObjectError, "Update", "You must set the SourceLib and DestLib properties before using this function."
  57.     End If
  58.     
  59.     On Error Resume Next
  60.     
  61.     'With out this function it could take
  62.     'up to a minute for libraries to freeup
  63.     CoFreeUnusedLibraries
  64.     
  65.     'Unregister DLL
  66.     Shell RegSvr32 & " /u /s """ & DestLib & """"
  67.     
  68.     'Make Backup DLL
  69.     FileCopy DestLib, BackupLib
  70.     
  71.     'Copy New DLL
  72.     FileCopy SourceLib, DestLib
  73.     
  74.     'Register New DLL
  75.     Shell RegSvr32 & " /s """ & DestLib & """"
  76.  
  77.     If Err = 0 Then
  78.         Update = True
  79.     Else
  80.         Err.Clear
  81.         Update = False
  82.     End If
  83.  
  84. End Function
  85.  
  86. Public Function Rollback() As Boolean
  87.     
  88.     If SourceLib = "" And DestLib = "" Then
  89.         Err.Raise vbObjectError, "Rollback", "You must set the SourceLib and DestLib properties before using this function."
  90.     End If
  91.     
  92.     On Error Resume Next
  93.     
  94.     'With out this function it could take
  95.     'up to a minute for libraries to freeup
  96.     CoFreeUnusedLibraries
  97.     
  98.     'Unregister DLL
  99.     Shell RegSvr32 & " /u /s """ & DestLib & """"
  100.     
  101.     'Copy Backup DLL
  102.     FileCopy BackupLib, DestLib
  103.     
  104.     'Registery Backup DLL
  105.     Shell RegSvr32 & " /s """ & DestLib & """"
  106.  
  107.     If Err = 0 Then
  108.         Rollback = True
  109.     Else
  110.         Err.Clear
  111.         Rollback = False
  112.     End If
  113.  
  114. End Function
  115.  
  116.  
  117.  
  118. Private Function FileExists(ByVal FileName As String) As Boolean
  119.     Dim fso
  120.     Set fso = CreateObject("Scripting.FileSystemObject")
  121.     FileExists = fso.FileExists(FileName)
  122.     Set fso = Nothing
  123. End Function
  124.  
  125. Private Function GetTempFileName(ByVal fName As String) As String
  126.     If InStr(fName, ".") > 0 Then
  127.         fName = Left(fName, InStr(fName, ".") - 1) & "_backup"
  128.     Else
  129.         fName = fName & "_backup"
  130.     End If
  131.     GetTempFileName = fName
  132. End Function
  133.